//
//  pdnewsTableViewCell.m
//  BAOASystem
//
//  Created by michael on 2018/3/6.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "pdnewsxqTableViewCell.h"
#import "pdnewsTableViewCell.h"

@implementation pdnewsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setDic:(NSDictionary *)dic{



_dic = dic;
[self initview];

}
- (void)initview{
 UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
         bgView.backgroundColor = [UIColor whiteColor];
    UIView *view  = [[UIView alloc]initWithFrame:CGRectMake(0, 29, KScreenWidth, 1)];
    view.backgroundColor  = [UIColor colorWithHexString:@"f0eff5"];
    [bgView addSubview:view];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-20, 29)];
label.text = NSLocalizedString(@"商品详情-商品信息", nil);
label.textColor = [UIColor colorWithHexString:@"484848"];
      [label setFont:[UIFont systemFontOfSize:16]];

   [bgView addSubview:label];
   [self addSubview:bgView];
NSArray *pricearray  =_dic[@"pdprice"];
NSArray *attributearray  =_dic[@"pdattribute"];
NSDictionary *dic  =_dic[@"product"];
     CGFloat height = [OAToolBox sizebyText:dic[@"keywords"] font:13 minsWidth:120];

if (pricearray.count==0) {
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 30, KScreenWidth, height+3*32+attributearray.count*32) style:UITableViewStylePlain];

}else{
_tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 30, KScreenWidth, height+2*32+attributearray.count*32+pricearray.count*32) style:UITableViewStylePlain];

}
_tableview.separatorStyle = NO;
_tableview.backgroundColor = [UIColor whiteColor];
//_tableview.frame = self.frame;
_tableview.dataSource = self;
_tableview.delegate = self;
self.tableview.bounces = NO;
[self addSubview:_tableview];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{NSArray *pricearray  =_dic[@"pdprice"];
NSArray *attributearray  =_dic[@"pdattribute"];


    return 3;

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *pricearray  =_dic[@"pdprice"];
NSArray *attributearray  =_dic[@"pdattribute"];
    switch (section) {
        case 0:
            return 1;
            break;
        case 1:
        if (pricearray.count==0) {
    return pricearray.count;
}else{
    return pricearray.count+1;

}
            
        case 2:
            return attributearray.count;
        default:
            return 1;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
 if (indexPath.section == 0) {
 static NSString *CellIdentifier1 = @"Cellbendititlepic1";

    pdnewsxqTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[pdnewsxqTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
        NSDictionary *productdic = _dic[@"product"];
 
cell.dic = productdic;
    return cell;
}else if (indexPath.section ==1){

if (indexPath.row ==0) {
 static NSString *CellIdentifier0 = @"Cellbendititlepic0";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
_label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 120, 32)];
       _label.textColor = [UIColor colorWithHexString:@"484848"];
       _label.numberOfLines = 0;
        [_label setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:_label];
           _label2 = [[UILabel alloc]initWithFrame:CGRectMake(130, 0, KScreenWidth-130, 32)];
           _label2.numberOfLines = 0;
       _label2.textColor = [UIColor colorWithHexString:@"484848"];
        [_label2 setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:_label2];
    }
    
        _label.text =NSLocalizedString(@"商品详情-订货量(件)", nil);
        _label2.text =NSLocalizedString(@"商品详情-价格(元/件)", nil);
       
    return cell;
}else{
 static NSString *CellIdentifier21 = @"Cellbendititlepic21";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier21];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier21];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 120, 32)];
                   label.numberOfLines = 0;

       label.textColor = [UIColor colorWithHexString:@"484848"];
        [label setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label];
           UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(130, 0, KScreenWidth-130, 32)];
                      label2.numberOfLines = 0;

       label2.textColor = [UIColor colorWithHexString:@"484848"];
        [label2 setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label2];
        NSArray *array = _dic[@"pdprice"];
        NSDictionary *dic =array[indexPath.row-1];
        label.text =[NSString stringWithFormat:@"%@-%@",dic[@"startNum"],dic[@"endNum"]];
        label2.text =[NSString stringWithFormat:@"%@",dic[@"price"]];
    
    return cell;
}
}else{
 static NSString *CellIdentifier31 = @"Cellbendititlepic31";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier31];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier31];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 120, 32)];
 label.numberOfLines = 0;
       label.textColor = [UIColor colorWithHexString:@"484848"];
        [label setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label];
           UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(130, 0, KScreenWidth-130, 32)];
                      label2.numberOfLines = 0;

       label2.textColor = [UIColor colorWithHexString:@"484848"];
        [label2 setFont:[UIFont systemFontOfSize:13]];
        [cell.contentView addSubview:label2];
        NSArray *array = _dic[@"pdattribute"];
        NSDictionary *dic =array[indexPath.row];
        label.text =[NSString stringWithFormat:@"%@",dic[@"name"]];
        label2.text =[NSString stringWithFormat:@"%@",dic[@"values"]];
    

    
    return cell;
}

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *pricearray  =_dic[@"pdprice"];
NSArray *attributearray  =_dic[@"pdattribute"];
NSDictionary *dic  =_dic[@"product"];
     CGFloat height = [OAToolBox sizebyText:dic[@"keywords"] font:13 minsWidth:120];
if (indexPath.section==0) {
if (pricearray.count ==0) {
    return 3*32+height;
}else{
    return 2*32+height;
    }
}else if(indexPath.section ==1){
   if (pricearray.count==0) {
    return 0;
}else{
    return 32;

}

}else{

return 32;
}

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
